package logic

import (
	"context"
	"rpc/pb/house"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHouseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseAddLogic {
	return &HouseAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HouseAddLogic) HouseAdd(req *types.HouseAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	addHouse, err := l.svcCtx.HouseRpc.AddHouse(l.ctx, &house.AddHouseRequest{
		HouseTitle:   req.HouseTitle,
		HousePrice:   float32(req.HousePrice),
		HouseImg:     req.HouseImg,
		HouseAddress: req.HouseAddress,
		HouseArea:    float32(req.HouseArea),
	})
	if err != nil {
		return &types.Response{
			Code: "500",
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}

	return &types.Response{
		Code: "200",
		Msg:  "添加成功",
		Data: map[string]interface{}{"addHouse": addHouse},
	}, nil
}
